/**
 * Created on Dec 21, 2011
 */
package com.prospring3.service.jpa;

import com.google.common.collect.Lists;
import com.prospring3.domain.Contact;
import com.prospring3.repository.ContactRepository;
import com.prospring3.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Clarence
 */

@Service("contactService")
@Repository
@Transactional
public class ContactServiceImpl implements ContactService {

    public ContactServiceImpl() {
     System.out.println("### ContactServiceImpl constructor  ###");
    }

    @Autowired
    private ContactRepository contactRepository;

    @Transactional(readOnly = true)
    public List<Contact> findAll() {
        return Lists.newArrayList(contactRepository.findAll());
    }

    @Transactional(readOnly = true)
    public Contact findById(Long id) {
        return contactRepository.findOne(id);
    }

    public Contact save(Contact contact) {
        return contactRepository.save(contact);
    }

    @Transactional(readOnly = true)
    public Page<Contact> findAllByPage(Pageable pageable) {
        return contactRepository.findAll(pageable);
    }

}
